#define _CRT_SECURE_NO_WARNINGS

bool isValid(char* s) {
    char* stack = (char*)malloc(sizeof(char) * strlen(s));
    int top = 0;

    while (*s != '\0')
    {
        if ((*s == '[') || (*s == '(') || (*s == '{'))
            stack[top++] = *s;

        else if (top == 0
            || (*s == ']' && stack[--top] != '[')
            || (*s == ')' && stack[--top] != '(')
            || (*s == '}' && stack[--top] != '{'))
        {
            return false;
        }

        s++;
    }

    if (top == 0)
        return true;
    else
        return false;
}